package com.jd.dlc.limit.biz;

import com.jd.dlc.limit.Trigger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: dlc
 * @ClassName DownActuator
 * @description:
 * @author: sizegang
 * @create: 2022-06-11
 **/
@Component
public class DownActuator {


    @Resource
    private Trigger trigger;

    /**
     * limited by the cache
     *
     * @param namespace
     * @param limitKey
     * @param joinPoint
     * @return
     * @throws Throwable
     */
    public Object isDisAllow(String namespace, String limitKey, ProceedingJoinPoint joinPoint, HttpServletResponse response) throws Throwable {
        Object[] args = joinPoint.getArgs();
        LimiterBencher bencher = (LimiterBencher) args[0];
        bencher.setAllowed(false);
        args[0] = bencher;
        trigger.triggerLimiter(namespace, limitKey, joinPoint, response, bencher);
        return joinPoint.proceed(args);
    }

}
